package com.sheng.whyclass.person.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.sheng.whyclass.R;


public final class MainActNavigateSixView extends FrameLayout implements View.OnClickListener {

    public static final class Component {
        public static final byte NAVIGATE_TEACHER_INFO = 1;
        public static final byte NAVIGATE_ADD_WORK = 2;
        public static final byte NAVIGATE_UPDATE_WORK = 3;
        public static final byte NAVIGATE_ADD_ANSWER = 4;
        public static final byte NAVIGATE_MANAGER_STUDENT = 5;
        public static final byte NAVIGATE_STATISTICS = 6;
    }

    public static interface ICallback {
        void onClicked(byte component);
    }

    private ImageView personIV;
    private ImageView addWorkIV;
    private ImageView updateWorkIV;
    private ImageView addAnswerIV;
    private ImageView managerStudentIV;
    private ImageView statisticsIV;


    private ICallback mCallback;

    public MainActNavigateSixView(Context context) {
        this(context, null);
    }

    public MainActNavigateSixView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MainActNavigateSixView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        LayoutInflater.from(context).inflate(R.layout.main_act_navigate_six_layout, this);

        personIV = (ImageView) findViewById(R.id.personIV);
       addWorkIV = (ImageView) findViewById(R.id.addWorkIV);
       updateWorkIV = (ImageView) findViewById(R.id.updateWorkIV);
       addAnswerIV = (ImageView) findViewById(R.id.addAnswerIV);
       managerStudentIV = (ImageView) findViewById(R.id.managerIV);
       statisticsIV = (ImageView) findViewById(R.id.statisticsIV);


        findViewById(R.id.personFrame).setOnClickListener(this);
        findViewById(R.id.addWorkFrame).setOnClickListener(this);
        findViewById(R.id.updateWorkFrame).setOnClickListener(this);
        findViewById(R.id.addAnswerFrame).setOnClickListener(this);
        findViewById(R.id.managerFrame).setOnClickListener(this);
        findViewById(R.id.statisticsFrame).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (mCallback == null) {
            return;
        }

        switch (v.getId()) {
            case R.id.personFrame: {
                mCallback.onClicked(Component.NAVIGATE_TEACHER_INFO);
                break;
            }
            case R.id.addWorkFrame: {
                mCallback.onClicked(Component.NAVIGATE_ADD_WORK);
                break;
            }
            case R.id.updateWorkFrame: {
                mCallback.onClicked(Component.NAVIGATE_UPDATE_WORK);
                break;
            }
            case R.id.addAnswerFrame: {
                mCallback.onClicked(Component.NAVIGATE_ADD_ANSWER);
                break;
            }
            case R.id.managerFrame: {
                mCallback.onClicked(Component.NAVIGATE_MANAGER_STUDENT);
                break;
            }
            case R.id.statisticsFrame: {
                mCallback.onClicked(Component.NAVIGATE_STATISTICS);
                break;
            }

        }
    }

    public void setCallback(ICallback callback) {
        mCallback = callback;
    }

    public void setSelected(byte component) {
        switch (component) {
            case Component.NAVIGATE_TEACHER_INFO: {
                personIV.setImageResource(R.drawable.person_selected);
                addWorkIV.setImageResource(R.drawable.person_unselected);
                updateWorkIV.setImageResource(R.drawable.person_unselected);
                addAnswerIV.setImageResource(R.drawable.person_unselected);
                managerStudentIV.setImageResource(R.drawable.person_unselected);
                statisticsIV.setImageResource(R.drawable.person_unselected);
                break;
            }
            case Component.NAVIGATE_ADD_WORK: {
                personIV.setImageResource(R.drawable.person_unselected);
                addWorkIV.setImageResource(R.drawable.person_selected);
                updateWorkIV.setImageResource(R.drawable.person_unselected);
                addAnswerIV.setImageResource(R.drawable.person_unselected);
                managerStudentIV.setImageResource(R.drawable.person_unselected);
                statisticsIV.setImageResource(R.drawable.person_unselected);
                break;
            }
            case Component.NAVIGATE_UPDATE_WORK: {
                personIV.setImageResource(R.drawable.person_unselected);
                addWorkIV.setImageResource(R.drawable.person_unselected);
                updateWorkIV.setImageResource(R.drawable.person_selected);
                addAnswerIV.setImageResource(R.drawable.person_unselected);
                managerStudentIV.setImageResource(R.drawable.person_unselected);
                statisticsIV.setImageResource(R.drawable.person_unselected);
                break;
            }
            case Component.NAVIGATE_ADD_ANSWER: {
                personIV.setImageResource(R.drawable.person_unselected);
                addWorkIV.setImageResource(R.drawable.person_unselected);
                updateWorkIV.setImageResource(R.drawable.person_unselected);
                addAnswerIV.setImageResource(R.drawable.person_selected);
                managerStudentIV.setImageResource(R.drawable.person_unselected);
                statisticsIV.setImageResource(R.drawable.person_unselected);
                break;
            }
            case Component.NAVIGATE_MANAGER_STUDENT: {
                personIV.setImageResource(R.drawable.person_unselected);
                addWorkIV.setImageResource(R.drawable.person_unselected);
                updateWorkIV.setImageResource(R.drawable.person_unselected);
                addAnswerIV.setImageResource(R.drawable.person_unselected);
                managerStudentIV.setImageResource(R.drawable.person_selected);
                statisticsIV.setImageResource(R.drawable.person_unselected);
                break;
            }
            case Component.NAVIGATE_STATISTICS: {
                personIV.setImageResource(R.drawable.person_unselected);
                addWorkIV.setImageResource(R.drawable.person_unselected);
                updateWorkIV.setImageResource(R.drawable.person_unselected);
                addAnswerIV.setImageResource(R.drawable.person_unselected);
                managerStudentIV.setImageResource(R.drawable.person_unselected);
                statisticsIV.setImageResource(R.drawable.person_selected);
                break;
            }

        }
    }
}
